import { R } from '@dataui/crud/crud';
import { NO_MERGE_BASE_MD } from '../constants';

export function NotMergeBase(...decorators: Array<MethodDecorator>) {
  // eslint-disable-next-line @typescript-eslint/ban-types
  return <TFunction extends Function, Y>(
    target: TFunction | object,
    propertyKey?: string | symbol,
    descriptor?: TypedPropertyDescriptor<Y>
  ) => {
    const oldKeys = new Set(Reflect.getMetadataKeys(target[propertyKey]));
    for (const decorator of decorators) {
      (decorator as MethodDecorator)(target, propertyKey, descriptor);
    }
    const addKeys = new Set(
      Reflect.getMetadataKeys(target[propertyKey]).filter(
        (i) => !oldKeys.has(i)
      )
    );
    R.set(NO_MERGE_BASE_MD, Array.from(addKeys), target[propertyKey]);

    console.log(
      'newMetadataKeys',
      oldKeys.values(),
      Reflect.getMetadataKeys(target[propertyKey]),
      addKeys
    );
  };
}
